<?php
/**
 * Controller de comentários de lead.
 *
 * @author    Chavão <freela@chavao.net>
 * @copyright Copyright (c) 2011, Chavão
 * @version   0.1
 */

class ComentarioController extends AppController
{
    public $layout = null;

    /**
     * Controller criar
     * @access public
     */
    public function criar()
    {
        $this->set('sLeadId',$this->data['lead_id']);
    }

    /**
     * Controller detalhar
     * @access public
     */
    public function detalhar()
    {
        $objCome = (object) $this->Comentario->first(array(
			'conditions' => array('come_id' => $this->data['come_id'])
        ));

        $this->set('objCome',$objCome);
    }

    /**
     * Controller listar
     * @access public
     */
    public function listar()
    {
        $arrComentario = $this->Comentario->all(array(
			'conditions' => array('lead_id' => $this->data['lead_id'])
        ));
          
        foreach($arrComentario as $k => $objCome)
        {

            $objCome = (object) $objCome;
             
            $objUsua = (object) $this->Usuario->first(array(
				'conditions' => array('usua_id' => $objCome->usua_id)
            ));
           
            $come_data = explode(' ',$objCome->come_data);
            $objCome->come_data = implode('/',array_reverse(explode('-',reset($come_data)))).' às '.substr($objCome->come_data,11,5);
            $objCome->usua_nome = $objUsua->usua_nome;

            $arrComentario[$k] = $objCome;
        }

        $this->set('arrComentario',$arrComentario);
    }

    /**
     * Controller salvar
     * @access public
     */
    public function salvar()
    {
        date_default_timezone_set('America/Sao_Paulo');
        $this->autoRender = false;
        $this->data['usua_id'] = $_SESSION['usua_id'];
        $this->data['come_data'] = date('Y-m-d H:i:s');

        $this->Comentario->save($this->data);

        $this->redirect($_SERVER['HTTP_REFERER']);
    }
}

?>
